<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>登入 - 个人博客系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all" th:href="@{/layui/css/layui.css}">
    <link rel="stylesheet" href="../../static/layui/css/admin.css" media="all" th:href="@{/layui/css/admin.css}">
    <link rel="stylesheet" href="../../static/layui/css/login.css" media="all" th:href="@{/layui/css/login.css}">
</head>
<body>

<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header">
            <h2>个人博客登录页面</h2>
            <font style="color: red"></font>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username"
                       for="LAY-user-login-email"></label>
                <input type="text" name="email" id="LAY-user-login-email" placeholder="邮箱"
                       class="layui-input">
                <div id="email_check"></div>
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password"
                       for="LAY-user-login-password"></label>
                <input type="password" name="password" id="LAY-user-login-password"
                       placeholder="密码" class="layui-input">
                <div id="password_check"></div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row">
                    <div class="layui-col-xs7">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                               for="LAY-user-login-vercode"></label>
                        <input type="text" name="vercode" id="LAY-user-login-vercode"
                               placeholder="图形验证码" class="layui-input">
                    </div>
                    <div class="layui-col-xs5">
                        <div style="margin-left: 10px;">
                            <img src="/getCode" th:src="@{/getCode}"
                                 class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
                        </div>
                    </div>
                </div>
                <div id="code_check"></div>
            </div>
            <div class="layui-form-item" style="margin-bottom: 20px;">
                <input type="checkbox" name="remember" lay-skin="primary" title="记住密码(十天)">
                <a href="forget.html" th:href="@{/user/forget}" class="layadmin-user-jump-change layadmin-link"
                   style="margin-top: 7px;">忘记密码？</a>
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-login-submit">登 入</button>
            </div>
            <div class="layui-trans layui-form-item layadmin-user-login-other">
                <!--<label>社交账号登入</label>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
                <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>-->
                <a href="/" th:href="@{/}" style="float: left"
                   class="layadmin-user-jump-change layadmin-link layui-hide-xs">返回首页</a>

                <a href="register.html" th:href="@{/user/toRegister}"
                   class="layadmin-user-jump-change layadmin-link">没有账号，请去注册帐号</a>
            </div>
        </div>
    </div>


    <!--<div class="ladmin-user-login-theme">
      <script type="text/html" template>
        <ul>
          <li data-theme=""><img src="{{ layui.setter.base }}style/res/bg-none.jpg"></li>
          <li data-theme="#03152A" style="background-color: #03152A;"></li>
          <li data-theme="#2E241B" style="background-color: #2E241B;"></li>
          <li data-theme="#50314F" style="background-color: #50314F;"></li>
          <li data-theme="#344058" style="background-color: #344058;"></li>
          <li data-theme="#20222A" style="background-color: #20222A;"></li>
        </ul>
      </script>
    </div>-->

</div>

<script src="../../static/layui/layui.js" th:src="@{/layui/layui.js}"></script>
<script src="../../static/js/jquery-1.8.3.min.js" th:src="@{/js/jquery-1.8.3.min.js}"></script>
<!-- th:inline="javascript" 加这个可以在js代码中使用thymeleaf模板 -->
<script type="text/javascript" th:inline="javascript">

    $("#LAY-user-get-vercode").click(function () {
        $(this).attr("src", "/getCode?" + new Date().getTime());
    });


    function checkEmail() {
        //1.定义正则表达式
        var pattern = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
        //2.获取员工姓名
        var email = $("#LAY-user-login-email").val();
        //3.判断 给出提示信息
        var flag = pattern.test(email);
        if (!flag) {
            //不合法
            $("#email_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">邮箱格式不正确</span>')
        } else {
            //合法
            $("#email_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">邮箱格式正确</span>');
        }

        return flag;
    }

    function checkPassword() {
        var pattern = /^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/;
        var password = $("#LAY-user-login-password").val();
        var flag = pattern.test(password);
        if (!flag) {
            //不合法
            $("#password_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入6-20位数字,字母,特殊字符中两种组合</span>')
        } else {
            //合法
            $("#password_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">密码格式正确</span>');
        }

        return flag;
    }


    function checkCode() {
        var pattern = /^[a-zA-Z0-9]{4}$/;
        var code = $("#LAY-user-login-vercode").val();
        var flag = pattern.test(code);
        if (!flag) {
            //不合法
            $("#code_check").html('<i style="color: red" class="layui-icon layui-icon-close"></i><span\n' +
                '                            style="color: red;">请输入4位包含数字或字母的验证码</span>')
        } else {
            //合法
            $("#code_check").html('<i style="color: green" class="layui-icon layui-icon-ok"></i><span\n' +
                '                            style="color: green;">验证码格式正确</span>');
        }

        return flag;
    }

    $("#LAY-user-login-email").blur(checkEmail);
    $("#LAY-user-login-password").blur(checkPassword);
    $("#LAY-user-login-vercode").blur(checkCode);


    $("#forget_form").submit(function () {
        var c1 = checkEmail();
        var c2 = checkPassword();
        var c3 = checkCode();
        return c1 && c2 && c3;
    });

    layui.use(['form', 'jquery','layer'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        var $ = layui.jquery;
        var layer = layui.layer;

        $(function () {
        if (/*[[${flag}]]*/"" == true) {
            layer.msg(/*[[${msg}]]*/);
        }
    });

        form.on('submit(LAY-user-login-submit)', function (data) {
            var c1 = checkEmail();
            var c2 = checkPassword();
            var c3 = checkCode();
            if (c1 && c2 && c3) {
                $.post(/*[[@{/securityLogin}]]*/"http://localhost:8081/securityLogin", data.field, function (data) {
                    if (data.login_info) {
                        if (data.admin) {
                            location.href = /*[[@{/admin/}]]*/"http://localhost:8081/admin/";
                        } else {
                            location.href = /*[[@{/}]]*/"http://localhost:8081/";
                        }
                    } else {
                        layer.msg(data.errorMsg);
                    }
                })
            } else {
                return false;
            }

        })
    });

    layui.use(['index', 'user', 'form'], function () {
        var $ = layui.$
            , setter = layui.setter
            , admin = layui.admin
            , form = layui.form
            , router = layui.router()
            , search = router.search;

        form.render();

        //提交


    });


</script>
</body>
</html>